package com.example.demo.design.demo14_observer;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 蔡超 on 2018/10/3.
 */
public abstract class AbstractSubject implements Subject {
    private Observer observer;

    private List<Observer> observerList = new ArrayList<Observer>();

    public Observer getObserver() {
        return observer;
    }

    public void setObserver(Observer observer) {
        this.observer = observer;
    }

    public List<Observer> getObserverList() {
        return observerList;
    }

    public void setObserverList(List<Observer> observerList) {
        this.observerList = observerList;
    }

    @Override
    public void attach(Observer observer){
        observerList.add(observer);
    };

    @Override
    public void detach(Observer observer){
        observerList.remove(observer);
    };


    @Override
    public void notifyObserver(){
        for (Observer observer : observerList) {
            observer.update();
        }
    }

    abstract void sendMsg();

}
